home *** CD-ROM | disk | FTP | other *** search
- *** expire.c_d Sun Apr 17 15:13:10 1994
- --- expire.c Fri Jun 24 14:23:10 1994
- ***************
- *** 23,28 ****
- --- 23,54 ----
- * '/', '\' or '.' to indicate subdirectories.
- * filename should NOT have the ending '.txt'
- */
- +
- + /* 25 March 1994
- + * Expire now expires messages stored in the NNTP server format.
- + * the additions to expire.dat 'sort of' follow the conventions for nntp
- + * in other areas of nos, namely the delimiter for nntp groups is bang (!)
- + * thus the format for expiring news items is
- + * !<newsgroup-name> age for example !ampr.vk5 21
- + * age still defaults to 21 days if not specified.
- + * automatic active and history file updates are done on each firing of
- + * the expiry process, only if at least one newsgroup was processed.
- + * all records are treated the same in the history file, and are expired
- + * when older than the largest number of days specified for any newsgroup.
- + * numbers of expiries in groups and history are both logged if > 0
- + * if you have any ideas on the above, dont keep them to yourself !! ;-)
- + * this code is not rigorously tested :-) vk5xxx march 1994
- + *
- + * April 7 1994
- + * added test for articles to ensure they are numeric. nos uses other control
- + * files in the newsgroup area (namely news.rc), nntp_expire would expire
- + * these happily, and update_nntp_active wqas confused by them (start = 0)
- + *
- + * June 25 1994
- + * Update the news.rc file with the lowest article number when the news.rc
- + * number is invalid.
- + */
- +
- #ifdef MSDOS
- #include <dir.h>
- #include <dos.h>
- ***************
- *** 41,46 ****
- --- 67,76 ----
- #include "smtp.h"
- #include "socket.h"
- #include "index.h"
- + #ifdef NNTPS
- + #include "dirutil.h" /* NNTP expire */
- + #include <limits.h> /* NNTP expire */
- + #endif
-
- #ifdef LINUX
- extern int unlink __ARGS((char *));
- ***************
- *** 99,104 ****
- --- 129,144 ----
- static void expire __ARGS((char *,int));
- static void Oldbidtick __ARGS((void *p));
-
- + #ifdef NNTPS /* for NNTP expiry */
- + /* NNTP Expire stuff */
- + static void expire_nntp __ARGS((char *, int));
- + static void update_nntp_history __ARGS((int));
- + static void update_nntp_active __ARGS((void));
- + static void update_newsrc __ARGS((int, int, char *));
- + static int convert_num __ARGS((char **));
- + static char *newsgroup_to_path __ARGS((char *));
- + #endif
- +
- int
- doexpire(argc,argv,p)
- int argc;
- ***************
- *** 140,145 ****
- --- 180,189 ----
- void *v1, *v2;
- {
- char line[80];
- +
- + #ifdef NNTPS /* for NNTP expiry */
- + int expire_nntp_history = 0;
- + #endif
- int age;
- char *cp;
- FILE *ctl;
- ***************
- *** 152,158 ****
- --- 196,207 ----
- /* read lines from the control file */
- while(fgets(line, sizeof(line), ctl) != NULLCHAR) {
- pwait(NULL); /* be nice */
- + #ifdef NNTPS /* for NNTP expiry */
- if((*line == '#') || (*line == '\n')) /* comment or blank line */
- + #endif
- + #ifndef NNTPS /* for NNTP expiry */
- + if((*line == '#') || (*line == '!') || (*line == '\n')) /* comment or blank line */
- + #endif
- continue;
- rip(line);
- /* terminate area name */
- ***************
- *** 163,174 ****
- --- 212,533 ----
- age = atoi(cp);
- }
- pwait(NULL); /* be nice */
- + #ifdef NNTPS /* for NNTP expiry */
- + if (*line == '!') /* Expire NNTP entry if line begins with ! */ {
- + expire_nntp(&line[1], age);
- + if (expire_nntp_history < age)
- + expire_nntp_history = age;
- + }
- + else
- + #endif
- expire(line, age);
- }
- fclose(ctl);
- + #ifdef NNTPS /* for NNTP expiry */
- + if (expire_nntp_history) {
- + update_nntp_history(expire_nntp_history);
- + update_nntp_active(); /* and news.rc */
- + }
- + #endif
- Eproc = 0;
- }
-
- + #ifdef NNTPS /* for NNTP expiry */
- + /*
- + expire nntp articles - the kludgomatic version.
- + these routines probably arent memory friendly, but they work.
- + more work needs to be done to make it meld more nicely into nos.
- + coded by brett england (future amateur) and rob vk5xxx.
- + */
- + static
- + int
- + convert_num( p )
- + char **p;
- + {
- + int i;
- + char *pp = *p;
- +
- + i = (*pp - '0') * 10 + *(pp+1) - '0';
- + (*p)+=2;
- + return (i);
- + }
- +
- + static
- + void
- + update_nntp_history(age)
- + int age;
- + {
- + FILE *old, *new;
- + char bckfile[FILE_PATH_SIZE];
- + char line[LINELEN];
- + char *p;
- + struct tm tm_time;
- + time_t expire_time, file_time, now;
- + int history_records_expired = 0;
- +
- + while(mlock(Newsdir,"history"))
- + pause(10000L);
- +
- +
- + expire_time = (long)age * 24L * 60L * 60L; /* days to seconds */
- + time(&now);
- +
- + /* Rename the history file, and use it to expire messages
- + */
- + sprintf(bckfile,"%s.bak",History);
- + unlink(bckfile);
- + if(rename(History,bckfile) == -1) {
- + log(-1,"NNTP Expire History: Can't rename %s to %s",History, bckfile);
- + return;
- + }
- +
- + if((old = fopen(bckfile,"rt")) == NULL) {
- + log(-1,"NNTP Expire History: Can't open file %s for read", bckfile);
- + return;
- + }
- +
- + if((new = fopen(History,"wt")) == NULL) {
- + log(-1,"NNTP Expire History: Can't open file %s for write",History);
- + return;
- + }
- +
- + for(;;) {
- + if(fgets(line, LINELEN, old) == NULL)
- + break;
- +
- + p = line;
- + while (*p != '\0' && *p != '>')
- + p++;
- + if (*p != '>') /* Some sort of corrupt line */
- + continue;
- + p+=2;
- + tm_time.tm_year = convert_num(&p);
- + tm_time.tm_mon = convert_num(&p)-1;
- + tm_time.tm_mday = convert_num(&p);
- + p++; /* Point to time component */
- + tm_time.tm_hour = convert_num(&p);
- + tm_time.tm_min = convert_num(&p);
- + tm_time.tm_sec = 0;
- +
- + file_time = mktime(&tm_time);
- +
- + if (file_time > ( now - expire_time ))
- + fputs(line, new);
- + else
- + history_records_expired++;
- + }
- +
- + fclose(new);
- + fclose(old);
- + rmlock(Newsdir,"history");
- +
- + if(history_records_expired > 0)
- + log(-1,"NNTP History: Expired %d records ...", history_records_expired);
- + }
- +
- + /* Check the news.rc file if the number contained is less than min
- + replace the news.rc file contents with min.
- + */
- + static
- + void
- + update_newsrc( min, max, path )
- + int min, max;
- + char *path;
- + {
- + FILE *newsrcfd;
- + char news_file[FILE_PATH_SIZE], line[LINELEN];
- + int no;
- +
- + sprintf(news_file,"%s/news.rc",path);
- + if((newsrcfd = fopen(news_file,"rt")) == NULL) {
- + log(-1,"NNTP News: Can't open file %s for read", news_file);
- + return;
- + }
- +
- + fgets(line, LINELEN, newsrcfd);
- + fclose(newsrcfd);
- +
- + no = atoi(line);
- + if((no < min) || (no > max)) {
- + if((newsrcfd = fopen(news_file,"wt")) == NULL) {
- + log(-1,"NNTP News: Can't open file %s for write", news_file);
- + return;
- + }
- + fprintf(newsrcfd,"%d",min);
- + fclose(newsrcfd);
- + }
- + }
- +
- + /* Update the active file and return the lowest news article
- + */
- + static
- + void
- + update_nntp_active() {
- + FILE *old, *new;
- + char bckfile[FILE_PATH_SIZE];
- + char line[LINELEN];
- + char *p, *path, *rpath;
- + int min, max;
- + int command, file_num;
- + struct ffblk *file;
- +
- + /* Rename the active file
- + */
- + sprintf(bckfile,"%s.bak",Active);
- + unlink(bckfile);
- + if(rename(Active,bckfile) == -1) {
- + log(-1,"NNTP Active: Can't rename %s to %s",Active, bckfile);
- + return;
- + }
- +
- + if((old = fopen(bckfile,"rt")) == NULL) {
- + log(-1,"NNTP Active: Can't open file %s for read", bckfile);
- + return;
- + }
- +
- + if((new = fopen(Active,"wt")) == NULL) {
- + log(-1,"NNTP Active: Can't open file %s for write",Active);
- + return;
- + }
- +
- + file = (struct ffblk *)mallocw(sizeof(struct ffblk));
- + for(;;) {
- + if(fgets(line, LINELEN, old) == NULL)
- + break;
- +
- + p = line;
- + while (*p != '\0' && ! isspace(*p))
- + p++;
- + if (*p == '\0')
- + continue;
- + *p = '\0';
- +
- + p++;
- + while(*p != '\0' && (isspace(*p) || isdigit(*p)))
- + p++;
- +
- + rpath = newsgroup_to_path( line );
- + path = wildcardize(rpath);
- +
- + command = 0;
- + min = INT_MAX;
- + max = INT_MIN;
- + for(;;) {
- + if (!nextname(command, path, file))
- + break;
- + command = 1; /* Find next */
- +
- + if (file->ff_name[0] == '.')
- + continue; /* ignore . and .. */
- +
- + file_num = atoi(file->ff_name);
- + if (file_num > 0) { /* should always be greater than 0 */
- + if (file_num < min)
- + min = file_num;
- + if (file_num > max)
- + max = file_num;
- + }
- + }
- + if (min == INT_MAX && max == INT_MIN) { /* No files */
- + min = 1;
- + max = 0;
- + }
- + update_newsrc(min, max, rpath);
- +
- + fprintf(new,"%s %05d %05d %s", line, max, min, p);
- + }
- + fclose(new);
- + fclose(old);
- + free(file);
- + }
- +
- + static
- + char
- + *newsgroup_to_path( group )
- + char *group;
- + {
- + FILE *f;
- + static char line[LINELEN];
- + char *cp;
- +
- + if((f = fopen(Pointer,"r")) == NULL)
- + return((char *)NULL);
- +
- + for (;;) {
- + if (fgets(line,LINELEN,f) == NULL)
- + break;
- +
- + if (strcspn(line," ") != strlen(group))
- + continue;
- +
- + if (strnicmp(group,line,strlen(group)) == 0) {
- + cp = (strchr(line,' ')) + 1;
- +
- + rip(cp);
- + fclose(f);
- + return (cp);
- + }
- + }
- + fclose(f);
- + return (NULL);
- + }
- +
- + void
- + expire_nntp(nntp_name, age)
- + char *nntp_name;
- + int age;
- + {
- + char *path;
- + int command = 0;
- + struct ffblk file;
- + struct tm tm_time;
- + time_t file_time, expire_time, now;
- + char nntp_file[FILE_PATH_SIZE];
- + char save_path[FILE_PATH_SIZE];
- + int file_num, expired = 0;
- +
- + /* Resolve nntp name into directory path */
- + if ((path = newsgroup_to_path( nntp_name )) == NULL)
- + return;
- +
- + expire_time = (long)age * 24L * 60L * 60L;
- + time(&now);
- + strcpy(save_path, path);
- + path = wildcardize(path);
- +
- + for(;;) {
- + if (!nextname(command, path, &file))
- + break;
- + command = 1; /* Find next */
- +
- + if (file.ff_name[0] == '.')
- + continue; /* ignore . and .. */
- +
- + file_num = atoi(file.ff_name);
- + /* should always be greater than 0 for a valid nntp article */
- + if (file_num > 0) {
- + /* only expire a file that is numeric :-) */
- + tm_time.tm_sec = 0; /* DOS doesn't store this */
- + tm_time.tm_min = (file.ff_ftime >> 5) & 0x3f;
- + tm_time.tm_hour = (file.ff_ftime >> 11) & 0x1f;
- + tm_time.tm_mday = file.ff_fdate & 0x1f;
- + tm_time.tm_mon = ((file.ff_fdate >> 5) & 0xf)-1;
- + tm_time.tm_year = (file.ff_fdate >> 9) + 80;
- +
- + file_time = mktime(&tm_time);
- +
- + if (( now - expire_time ) > file_time) {
- + sprintf(nntp_file, "%s/%s", save_path, file.ff_name);
- + unlink(nntp_file);
- + expired++;
- + }
- + }
- + }
- + if(expired)
- + log(-1,"NNTP Expired: %d in %s",expired, nntp_name);
- + }
- + #endif /*nntps*/
- +
- void
- expire(filename,age)
- char *filename;
- *** dirutil.h_d Sun Apr 17 15:15:26 1994
- --- dirutil.h Fri Jun 24 13:41:42 1994
- ***************
- *** 34,39 ****
- --- 34,41 ----
- extern int findfirst(char *pat, struct ffblk *ff, int attr);
- extern int findnext(struct ffblk *ff);
-
- + #else
- + #include <dir.h>
- #endif
-
- struct cur_dirs {
- ***************
- *** 55,60 ****
- --- 57,67 ----
- void free_dirs(struct cur_dirs * dirs);
- int dir_ok(char * path,struct cur_dirs * dirs);
- int dircmd __ARGS((int argc,char *argv[],void *p));
- +
- + /* Made public for nntp expiry */
- + int nextname __ARGS((int command, char *name, struct ffblk *sbuf));
- + char *wildcardize __ARGS((char *path));
- +
- #ifdef MSDOS
- int dosfnchr __ARGS((int ch));
- #endif
- *** dirutil.c_d Sun Apr 17 15:13:06 1994
- --- dirutil.c Fri Jun 24 12:01:34 1994
- ***************
- *** 55,64 ****
- #ifdef notdef
- static int getdir_nosort __ARGS((char *path,int full,FILE *file));
- #endif
- - static int nextname __ARGS((int command, char *name, struct ffblk *sbuf));
- static void print_free_space __ARGS((char *path,FILE *file,int n));
-
- - static char *wildcardize __ARGS((char *path));
- extern void crunch __ARGS((char *buf,char *path));
-
- #define REGFILE (FA_DIREC)
- --- 55,62 ----
- ***************
- *** 85,91 ****
- }
-
- /* find the first or next file and lowercase it. */
- ! static int
- nextname(command, name, sbuf)
- int command;
- char *name;
- --- 83,89 ----
- }
-
- /* find the first or next file and lowercase it. */
- ! int
- nextname(command, name, sbuf)
- int command;
- char *name;
- ***************
- *** 305,311 ****
- }
-
- /* fix up the filename so that it contains the proper wildcard set */
- ! static char *
- wildcardize(path)
- char *path;
- {
- --- 303,309 ----
- }
-
- /* fix up the filename so that it contains the proper wildcard set */
- ! char *
- wildcardize(path)
- char *path;
- {
-